﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProtoBuf;

namespace SimpleInfrastructure.Serialize
{
    public class SerializerProvider
    {
        public static ISerializer GetSerializer<T>(T serialObject)
        {
            Type t = serialObject.GetType();
            if (t.GetCustomAttributes(true).Any(a => a is ProtoContractAttribute))
            {
                return new ProtoBufSerializer();
            }
            else
            {
                return new NJsonSerializer();
            }
        }
        public static ISerializer GetSerializer<T>()
        {
            Type t = typeof(T);
            if (t.GetCustomAttributes(true).Any(a => a is ProtoContractAttribute))
            {
                return new ProtoBufSerializer();
            }
            else
            {
                return new NJsonSerializer();
            }
        }
        public static ISerializer GetBytesSerializer<T>(T serialObject)
        {
            Type t = serialObject.GetType();
            if (t.GetCustomAttributes(true).Any(a => a is ProtoContractAttribute))
            {
                return new ProtoBufSerializer();
            }
            else
            {
                return new BinarySerializer();
            }
        }
        public static ISerializer GetBytesSerializer<T>()
        {
            Type t = typeof(T);
            if (t.GetCustomAttributes(true).Any(a => a is ProtoContractAttribute))
            {
                return new ProtoBufSerializer();
            }
            else
            {
                return new BinarySerializer();
            }
        }

        public static ISerializer GetDefaultStringSerializer()
        {
            return new NJsonSerializer();
        }

        public static ISerializer GetDefaultBytesSerializer()
        {
            return new BinarySerializer();
        }

        public static ISerializer GetStringSerializer<T>(T serialObject)
        {
            return new NJsonSerializer();
        }

        public static ISerializer GetStringSerializer<T>()
        {
            return new NJsonSerializer();
        }
    }
}
